  import { defineConfig, loadEnv } from 'vite'
  import react from '@vitejs/plugin-react'
  import path from 'node:path'
  import autoprefixer from 'autoprefixer'

  export default defineConfig(({ mode }) => {
    // Load .env
    const env = loadEnv(mode, process.cwd(), '')
    process.env = { ...process.env, ...env }

    return {
      base: './',
      build: {
        outDir: 'build',
      },
      css: {
        postcss: {
          plugins: [
            autoprefixer({}), // add options if needed
          ],
        },
      },
      define: {
        // vitejs does not support process.env so we have to redefine it
        'process.env': process.env,
      },
      esbuild: {
        loader: 'jsx',
        include: /src\/.*\.jsx?$/,
        exclude: [],
      },
      optimizeDeps: {
        force: true,
        esbuildOptions: {
          loader: {
            '.js': 'jsx',
          },
        },
      },
      plugins: [react()],
      resolve: {
        alias: [
          {
            find: 'src/',
            replacement: `${path.resolve(__dirname, 'src')}/`,
          },
        ],
        extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.scss'],
      },
      server: {
        port: 3000,
        proxy: {
          // https://vitejs.dev/config/server-options.html
        },
      },
    }
  })
